<!--
关注
-->
<template>
    <div class="subscrib-box" @click="subscrib" :class="{'cancel':subFlag}" v-if="author.id != 1">
        <span class="subscrib" v-if="!subFlag">+&nbsp;关注</span>
        <span class="subscrib" v-else>已关注</span>
    </div>
</template>

<script>
    import {appService} from '../../service/appService'
    import {actService} from '../../service/activityService'
    import {commonService} from '../../service/commonService'
    export default {
        props: ['author'],
        data(){
            return{
                subFlag:false
            }
        },
        mounted() {
            let that = this
            if(appService.checkLogin()) {
                if(that.author.id ==1) return;
                actService.isFollow({adminId: that.author.id}).then(function (res) {
                    if (res.data.success) {
                        that.subFlag = res.data.datas
                    }
                })
            }
            // this.subFlag = this.author.isFollow
           // console.log(this.author)
        },
        methods: {
            subscrib(){
                let that = this;
                if(appService.checkLogin()){
                    if(!that.subFlag){
                        actService.myFollow({adminId:that.author.id}).then(function(res){
                            if(res.data.success){
                                that.subFlag = true
                            }
                        })
                    }else{
                        actService.cancelFollow({adminId:that.author.id}).then(function(res){
                            if(res.data.success) {
                                that.subFlag = false
                            }
                        })
                    }

                }else{
                    commonService.showLoginModal(that)
                    setTimeout(function(){
                        that.$router.push({name:'login'})
                    },500)
                }

            }
        }
    }
</script>

<style lang="less">
    .subscrib-box {
        display:inline-block;
        padding:0 .4rem;
        border-radius:1.4667rem;
        border:1px solid #333;
        .subscrib{
            line-height:.6933rem;
            font-size: .32rem;
            color: #333333;
        }
    }
    .subscrib-box.cancel{
        border:1px solid #ddd;
        .subscrib {
            color: #ddd;
        }

    }

</style>